<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-user-edit" th:object="${user}">
        <input name="userId"  type="hidden"  th:field="*{userId}" />
        <input name="deptId"  type="hidden" id="treeId"/>
        <div class="form-group">
            <label class="col-sm-3 control-label">用户名：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="userName" id="userName" th:field="*{userName}" readonly>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">性别：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="sex" th:field="*{sex}" readonly>
            </div>
        </div>
       <!-- <div class="form-group">
            <label class="col-sm-3 control-label">身份证号：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="idCard" th:field="*{idCard}" readonly>
            </div>
        </div>-->
        <div class="form-group">
            <label class="col-sm-3 control-label">部门名称：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="deptName" onclick="selectDeptTree()"  id="treeName" th:field="*{dept.deptName}">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">岗位：</label>
            <div class="col-sm-8">
                <label th:each="role:${roles}" class="check-box">
                    <input name="role" type="checkbox" th:value="${role.roleId}" th:text="${role.roleName}" th:checked="${role.flag}" th:disabled="${role.status == '1'}">
                </label>
            </div>
        </div>
        <!--<div class="form-group">
            <label class="col-sm-3 control-label">身份证人像面：</label>
            <div class="col-sm-5">
                <div class="fileinput fileinput-new" data-provides="fileinput">
                    <div class="fileinput-preview thumbnail" data-trigger="fileinput" style="width: 300px; height: 220px;">
                        <img th:src="${user.idCardIsUrl}">
                    </div>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">身份证国徽面：</label>
            <div class="col-sm-5">
                <div class="fileinput fileinput-new" data-provides="fileinput">
                    <div  class="fileinput-preview thumbnail" data-trigger="fileinput" style="width: 300px; height: 220px;">
                        <img th:src="${user.idCardTheUrl}">
                    </div>
                </div>
            </div>
        </div>-->
        <div class="form-group">
            <label class="col-sm-3 control-label">审核通过：</label>
            <div class="col-sm-5">
                <label class="radio-box"><input type="radio" checked="" value="2" name="reviewStatus"> 通过</label>
                <label class="radio-box"><input type="radio" value="3" name="reviewStatus"> 拒绝</label>
            </div>
        </div>
    </form>
</div>
<div th:include="include::footer"></div>
<script th:src="@{/ajax/libs/select/select2.js}"></script>
<script>
    $("#form-user-edit").validate({
    });

    function submitHandler() {
        if ($.validate.form()) {
            edit();
        }
    }

    function edit() {
        var userId = $("input[name='userId']").val();
        var deptId = $("input[name='deptId']").val();
        var roleIds = $.form.selectCheckeds("role");
        var reviewStatus = $("input[name='reviewStatus']:checked").val();
        if (reviewStatus == 2) {
            if (deptId == ""){
                $.modal.msgError("请选择部门");
                return;
            }
            if (roleIds == ""){
                $.modal.msgError("请选择岗位职务");
                return;;
            }
        }

        $.ajax({
            cache : true,
            type : "POST",
            url : ctx + "system/user/edit",
            data : {
                "userId": userId,
                "deptId": deptId,
                "roleIds": roleIds,
                "reviewStatus": reviewStatus
            },
            async : false,
            error : function(request) {
                $.modal.alertError("系统错误");
            },
            success : function(data) {
                $.operate.successCallback(data);
            }
        });
    }

    /*用户管理-修改-选择部门树*/
    function selectDeptTree() {
        var deptId = $.common.isEmpty($("#treeId").val()) ? "100" : $("#treeId").val();
        var url = ctx + "system/dept/selectDeptTree/" + deptId + "?attrId=[[${user.attrId}]]";
        var options = {
            title: '选择部门',
            width: "380",
            url: url,
            callBack: doSubmit
        };
        $.modal.openOptions(options);
    }

    function doSubmit(index, layero){
        var tree = layero.find("iframe")[0].contentWindow.$._tree;
        if ($.tree.notAllowParents(tree)) {
            var body = layer.getChildFrame('body', index);
            $("#treeId").val(body.find('#treeId').val());
            $("#treeName").val(body.find('#treeName').val());
            layer.close(index);
        }
    }
</script>
</body>
</html>
